<?php

$baseDir = dirname(dirname(dirname(dirname(__FILE__))));
set_include_path(get_include_path().PATH_SEPARATOR.$baseDir.PATH_SEPARATOR.$baseDir.'/incubator');

include '../../testingfunctions.php';
include 'Pone/Pone_Exception.php';
include 'Pone/Database/Pone_Database_ConnectionFactory.php';
include_once './dbconfig.php'; // $config is defined here
include_once './test_setup.php'; // refreshTestData() is defined here

try
{
    refreshTestData($config);
    $conn     = Pone_Database_ConnectionFactory::getConnection($config);
    $pstmt    = $conn->prepareStatement('SELECT * FROM test2');
    $pstmt->execute();
    $rs       = $pstmt->getResultSet();
    $valid    = $rs->absolute(2);
    assertTrue($valid === true, 'Expected: Be able to move the cursor to the second row (2) of result set. ');
    echo '<br />';

    $valid    = $rs->absolute(8);
    assertTrue($valid === false, 'Expected: Unable to move to eighth row (8) of result set. ');
    echo '<br />';

    $valid    = $rs->absolute(7);
    assertTrue($valid === true, 'Expected: Be able to move to seventh row (7 and the last row) of result set. ');
    echo '<br />';

    $rowNum   = $rs->currentRowNumber();
    assertTrue($rowNum === 7, 'Expected: The current row number must be 7. ');
    echo '<br />';

    $row      = $rs->currentRow();
    assertTrue($row === array('id' => 7, 'username' => 'pcdinh7', 'seq_number' => 7),
    'Expected: Row returned contains an id value of 7, username value of pcdinh7 and seq_number value of 7. ');
    echo '<br />';
    $valid    = $rs->absolute(2);
    $row      = $rs->currentRow();
    assertTrue($row === array('id' => 2, 'username' => 'pcdinh2', 'seq_number' => 2),
    'Expected: Be able to move the cursor to second row of the result set and row returned contains an id value of 2, username value of pcdinh2 and seq_number value of 2. ');

    $rs->close();
    // Free resources
    $pstmt->close();
}
catch (Pone_Exception_DatabaseAccess $ex)
{
    echo implode('. ', $ex->getTraceMessages());
    echo '<br />';
    echo $ex->getNativeMessage();
}
catch (Exception $ex)
{
    echo $ex->getMessage();
}

$conn->close();
?>